package com.ee.chat.common.generator;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MysqlGenerator {
    public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/chat-common/src/main/java");
        gc.setOpen(false);
        // gc.setSwagger2(true); 实体属性 Swagger2 注解
//        gc.setActiveRecord(true);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        gc.setFileOverride(true);
        mpg.setGlobalConfig(gc);

        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUrl("jdbc:mysql://cyhy-polardb.rwlb.rds.aliyuncs.com:3306/pp2_dev");
        dsc.setUsername("dev");
        dsc.setPassword("dev@2020");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.ee.chat.common");
        pc.setEntity("entity");
        pc.setMapper("dao");
        pc.setXml("dao.mapper");
        mpg.setPackageInfo(pc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);  //映射到实体的命名策略
//        strategy.setTablePrefix("e_");  //表前缀
        strategy.setInclude("user_call_log");  //需要包含的表名
        strategy.setEntityTableFieldAnnotationEnable(true); //生成实体时，生成字段注解
        mpg.setStrategy(strategy);

        TemplateConfig tc = new TemplateConfig();
        tc.disable(TemplateType.CONTROLLER, TemplateType.SERVICE);
        mpg.setTemplate(tc);

        mpg.execute();
    }
}
